<?php

namespace App\Models\Api;

use EasyWeChat\Factory;
use Illuminate\Support\Facades\Log;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;
use \Illuminate\Support\Facades\Hash;

class Users extends Authenticatable implements JWTSubject
{
    use Notifiable;


    protected  $table = 'users';

    public  $guarded = [];

    public  $timestamps = true;

    /**
     * password bcrypt
     *
     * @return mixed
     */
    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = bcrypt($value);
    }

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }


    /**
     * 获取信息
     * @param $data
     * @return array|string
     */
    public static function getInfo($data)
    {
        $info = self::where(['id' => $data['user']['user_id']])->first();
        if (!$info) return result_json(409, '信息不存在');
        return result_json(200, '成功', ['info' => $info]);
    }


}